package com.xiguaji.tiktok.v1.tiktok.comparison.repository;

import com.xiguaji.tiktok.v1.tiktok.comparison.dto.BloggerResponse;
import com.xiguaji.tiktok.v1.tiktok.comparison.model.Comparison;
import org.springframework.data.jdbc.repository.query.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;
import java.util.Optional;

public interface ComparisonRepository extends CrudRepository<Comparison,Long> {

    Optional<Comparison> findByUserIdAndUid(long userId,long uid);

    @Query("SELECT b.o_uid uid,REPLACE (REPLACE (b.o_avatar168, 'sign-sg', 'amd-va'), 'sign-va', 'amd-va') avatar,b.o_enterprise_verify_reason enterprise_verify_reason,b.o_unique_id unique_id,b.custom_verify,b.o_nickname nickname,b.o_region region" +
            " FROM comparison c " +
            "LEFT JOIN blogger_main b ON c.uid = b.o_uid " +
            "WHERE user_id = :userId  ORDER BY c.create_time ")
    List<BloggerResponse> findByUserId(long userId);

    int countByUserId(long userId);
}
